package com.chixing.day18_thread.word;

public class PublicDemo {
    private int num = 1;

    public synchronized void getA(){
        if (num %3 == 1){
            num++;
            notifyAll();
            System.out.print("A");

        }else {
            try {
                this.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }

    public synchronized void getB(){
        if (num %3 == 2){
            num++;
            notifyAll();
            System.out.print("B");

        }else {
            try {
                this.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }

    public synchronized void getC(){
        if (num %3 == 0){
            num++;
            notifyAll();
            System.out.print("C");
            System.out.println();
        }else {
            try {
                this.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
